Golang html/template.JSEscapeString function example
package html/template
JSEscapeString returns the escaped JavaScript equivalent of the plain text data s(1st parameter).
Golang html/template.JSEscapeString function usage example
package main
import (
"fmt"
"html/template"
)
func main() {
s := "<script>alert('xss attack!')</script>"
final := template.JSEscapeString(s)
fmt.Println(final)
}
Output :
\x3Cscript\x3Ealert(\'xss attack!\')\x3C/script\x3E
Reference :
Advertisement
Something interesting
Tutorials
+5.8k Golang : Find change in a combination of coins example
+13.7k Golang : Image to ASCII art example
+5.2k Golang : Convert lines of string into list for delete and insert operation
+7.4k Golang : Individual and total number of words counter example
+9.8k Golang : Get current, epoch time and display by year, month and day
+12.6k Golang : Transform comma separated string to slice example
+7.5k Golang : Detect sample rate, channels or latency with PortAudio
+10.1k Golang : Compare files modify date example
+14.4k Golang : How to pass map to html template and access the map's elements
+18.9k Golang : Read input from console line
+7.4k Golang : Check to see if *File is a file or directory